Skip to content

VN36: parent(n).par.key in expressions (stacked on #5 and #4) - #6

Merged
laubsauger merged 5 commits into
laubsauger:mainfrom
drmbt:pr/drmbt-parent-expr-2026-10-06
Oct 8, 2026
Merged

laubsauger merged 5 commits into
laubsauger:mainfrom
drmbt:pr/drmbt-parent-expr-2026-10-06

Conversation

@drmbt

@drmbt drmbt commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Stacked on #5, which is stacked on #4. Draft until both merge. Until they do, the diff below also shows their commits. Review only the last three commits (compare a5c77599...b04d4d78): 35 files, +1402 / −41. Merge order: #4 → #5 → this. Once the two below land with merge commits, their commits drop out of this diff with no rebase.

Part of stage 1 of the COMP-model proposal (#3, docs/comp-model-2026-10-06/01-comps-as-folders.md §2.3 and proposal 02).

The problem

An expression could not read its own component's published parameter. So stage-previz-8 keeps 17 Constant "knob holders" for formulas to read. With this change, parent().par.gain * 0.5 + op('lfo1').chan.value is one expression.

The change

This follows TD's model: parent() names the COMP, and .par.key is evaluated once, where it lives. Readers get the number, not the formula.

  1. f0a14490 grammar:
    • parent() / parent(n) followed by .par.<key>, with an optional component. Every other shape is refused at parse time, and the error gives the form to write.
    • A bare parent stays a variable name, and parent.<key> binds parse as before.
    • The AST node records its span, so a caller with the scope can rewrite the read in place.
  2. 34a282b0 reader: op('<instance>').par.<key> reads a dissolved instance's page.
    • Flattening deletes the instance node. T1485b answered that for .chan; this answers it for .par.
    • The flattening hands over each instance's page (FlatteningReads.instancePages). A name no flat node carries is resolved there, through the same targetOf as any other node.
    • An animated knob is evaluated once per frame at its publisher.
    • instancePages is REQUIRED (T1551b's rule), so every reader site states it.
    • This is a stage-1 bridge: when a COMP is a real node (stages 2–3), the map retires.
  3. b04d4d78 the rewrite:
    • Flatten (compiler/parent-references.ts, beside effectiveParameters) rewrites parent(n).par.key to op('<the n-th enclosing instance>').par.key.
    • Same rule as §V81: only the published page is reachable. A key the page does not publish, a root node, or a reach past the outermost component is refused by name: compiler/parent-reference-unknown-key or -no-parent. The parameter keeps its static value (§V108); it never reads 0.
    • Value-graph order, liveness and pruning (prune.ts) follow a read through the page. Without the pruning change, a node read only through a page would be pruned as dead.
    • component.detach rewrites parent() for where the copies land, and says what it cannot carry.
    • parent.<key> binds are unchanged; migrating them is separate work.
  • Design note: docs/parent-expressions-2026-10-06.md.

Tests

  • Gate (Dawn, src/tests/headless/parent-expressions.gpu.test.ts, through the app's commands): a Solid is saved as "Lamp" with red = parent().par.gain and green = 1 - parent().par.gain, then placed twice, at gain 1 and gain 0. The two copies render pure red and pure green.
    • With the publish cut, both hold static black and four unknown-key warnings are reported.
    • An animated page knob gives two colours on two frames.
    • Red-verified: with the rewrite off, all three fail on the evaluator's refusal.
  • Headless, each red-verified: nesting, nested page values, a carried slot, root, too deep, value-graph order, liveness, detach, and the per-frame values-only compile equal to the full compile.
  • Ladder: named tests plus 4 GPU neighbours, pnpm test:gates (64 files / 3,706), pnpm typecheck, pnpm lint, pnpm build.

Proposed §T row

T____|.|**`parent()` IN EXPRESSIONS (stage 1 of #3).** `parent(n).par.key` rewritten at flatten to `op('<n-th enclosing instance>').par.key`; the reader evaluates a dissolved instance's published page once per frame (`FlatteningReads.instancePages`, a bridge until COMPs are real nodes); unknown key / no parent refused by name, static kept; value-graph order, liveness, prune and detach follow the page. Repro on Dawn: one component placed twice renders red and green from its own page.|T1701b,T1485b,T1551b,V81,V108

🤖 Generated with Claude Code

drmbt and others added 5 commits October 6, 2026 19:27
The mesh loader wrote a file's measured facts (vertices, triangles, parts,
joints, clips, clipFrames, frameOrigin, bounds) onto the node it found with
getGraph().nodes[nodeId]. An inner node's id is flattened (instance/inner),
the document does not hold it, so the write never happened and the node
compiled as the one-vertex stand-in: it drew nothing.

The facts now land as that instance's overrides of the inner node
(state.componentOverrides, keyed internalParameterPath), which flattening
already applies over the definition. Each instance keeps its own size, two
instances can load different files, and the shared definition is untouched.

- setParameters gains an optional internalNodeId, on the precedent of
  setNodeChannelMask's: one op through the bus, so undo, audit and the
  revision check come with it. A non-instance and a nested path are refused
  by name (parameter.internal.notComponent / .nested).
- "Already sized" reads the flattened node (definition plus overrides).
- Ids are split and joined through domain/components/addressing.ts
  (enteredThrough, toInstance), per T1695b's gate.
- One level only: an override key is <node>/<key>, so a mesh inside a
  nested component is refused as mesh.unsizable. mesh.component is retired.

Tests: the literal bug on Dawn (the app's loader hook sizes two instances
of one component loading different files, and each Geometry renders only
its own instance's mesh); undo of the measure; the definition untouched;
the nested refusal. Red-verified against the old lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
COMP-model stage 1 (proposal 01 §4). B41 renumbers the names inside the
second and later instances of a component, so an outer reference could
reach in only by a bare name, and a bare name binds the first copy. Three
instances of a Projector component could not be bound by one Render.

- `op('instance/node')`, `../node`, and path-valued source references
  (every SOURCE_REFERENCE_PARAMETERS entry). Relative only. A segment is
  a node's name as written in its own graph. Parsing and the walk live in
  addressing.ts, the one joiner.
- Resolved once, at flatten (path-references.ts): each path is rewritten
  to its target's unique flat label, so synthesis, the op() reader,
  liveness and channels are unchanged. A path that reaches nothing stays
  as written and is refused by name.
- Bare names resolve as before. New warning compiler/reference-cross-scope
  when one reaches INTO an instance the referrer is not in, with the path
  to write and how many copies carry the name. Reading outward is silent.
  No shipped example raises it; stage-previz-8 raises 52.
- §V128: a rename moves the head of a path written in its graph. B41's
  uniquing does not touch paths.
- `/` is refused in labels at the exact doors (node.label.separator); the
  suggestion is TD's validName form (roleFromText). node.rename already
  converts it.

Gate (Dawn, projector-paths.gpu.test.ts): one Projector component placed
three times through the app's commands, each with its own aim and pure
colour; the outer Render binds all three by path and each third of the
stage is lit in its own colour only. Red-verified with the pass removed.
The bare name, the old way, lights the left third alone and now warns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`parent()` / `parent(n)` followed by `.par.<key>` with an optional component,
refused at parse time in every other shape with the form to write. A bare
`parent` stays a variable name. The AST node records its span, so a caller
with the scope can rewrite the read in place (`parent-reads.ts`) without
re-serialising or pattern-matching the expression.

Nothing evaluates one yet: the evaluator refuses it as `reference.unreadable`
("not inside a component") rather than reading 0. The flattener's rewrite
lands in the next commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Flattening deletes the instance node, so the compiler's reader, over the
flat graph, found nothing called `rig1`. T1485b answered that for `.chan`.
This answers it for `.par`: the flattening hands over each instance's page
(`FlatteningReads.instancePages`, label → the instance as flattened plus
its published schema), and a name no flat node carries is resolved there,
through the same `targetOf` as any node. An animated knob is evaluated
once per frame at its publisher, and the reader gets a number.

This is the read `parent()` becomes (next commit). It is a stage-1 bridge:
when a COMP is a real node (proposal 01 stages 2–3) the name index finds it
and the map retires.

`instancePages` is REQUIRED on `FlatteningReads` (T1551b's rule), so every
reader site says it: the compile and per-frame compile (beside
`resolution.instances`), the value graph, the OSC pump, parameter
commands, the controls pane, the inspector (the root flattening's pages
while inside an instance) and the test harnesses.

Gate (integration, real flattener/value graph/compiler): page value read
and followed; an animated page knob at two frames; a compound component;
an unknown key refused with the nearest spelling; the per-frame
values-only compile equal to the full compile and moving. Red-verified:
reader lookup off fails all five; the per-frame compile's pages off fails
the last.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
COMP-model proposal 01 §2.3. An expression could not read its own
component's published parameter, so stage-previz-8 keeps 17 Constant
"knob holders" for formulas to read. Now `parent().par.gain * 0.5 +
op('lfo1').chan.value` is one expression.

TD's model: `parent()` names the COMP, and `.par.key` is evaluated once,
where it lives; readers get the number, not the formula.
- Flatten resolves a NAME (`compiler/parent-references.ts`, beside
  `effectiveParameters`): `parent(n).par.key` becomes
  `op('<the n-th enclosing instance>').par.key`. It runs as each node's
  parameters are made, the instance's own page included, so a page slot
  T1017 carries inward keeps the `parent()` it was written with.
- The reader reads that instance's page per frame (previous commit).
- Same rule as §V81: only the published page is reachable. A key it does
  not publish, a root node, or reaching past the outermost component is
  refused by name (`compiler/parent-reference-unknown-key`,
  `-no-parent`, class never), and the parameter keeps its static (§V108).
  It never reads 0.
- Value-graph order and liveness follow a read through the page, so a
  page knob reading an LFO orders its readers after it and keeps what it
  reads alive. T1485b's `.chan` branch no longer swallows `.par` reads.
- `component.detach` rewrites `parent()` for where the copies land, by
  the rule it applies to `parent.` binds. What it cannot carry is said.
- `parent.<key>` binds are unchanged (VN38 migrates them).
- Fixes the grammar commit's case fallthrough (lint).

Gate (Dawn, parent-expressions.gpu.test.ts, through the app's commands):
a Solid saved as "Lamp" with red = parent().par.gain and green =
1 - parent().par.gain, placed twice at gain 1 and 0, renders pure red and
pure green. Cut the publish: both hold static black and four unknown-key
warnings. An animated page knob: two frames, two colours. Red-verified
(rewrite off: all three fail on the evaluator's refusal). Headless:
nesting, nested page values, a carried slot, root, too deep, value-graph
order, liveness, detach, each red-verified.

Design and follow-ups: docs/parent-expressions-2026-10-06.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner

This is the next feature in the same chain: VN35 now exists on main through repaired #13, and VN33's useful coverage landed through #12 without restoring #4's unchecked writer.

I ported only this PR's three VN36 commits onto that implementation. Its initial 81 focused tests and typecheck passed, but additional reproductions exposed unresolved paths on dissolved published pages, invisible parent/page cycles, and publication that activated a latent cycle. The repair also handles whitespace that the parser accepted but the span walker missed.

The fixes are now published in #14. They keep the original grammar, per-frame page reader, parent rewrite, liveness/pruning and detach work, while sharing scope/path and cycle rules with the repaired VN35. The real app-command lamp fixture has a CPU compiler proof, with required Dawn checks kept explicit.

The replacement preserves the contributor's history and is based on current main. The connector cannot update this fork branch, so this draft remains unchanged until the replacement's CI passes and it lands; it will then be closed here with the final link and validation result.

@laubsauger
laubsauger merged commit 3634da5 into laubsauger:main Oct 8, 2026
3 checks passed

Copy link
Copy Markdown
Owner

The feature from this PR has now landed on main through #14 (merge commit 67b77ed). The replacement retains all three VN36 contributor commits and builds on the repaired path-name implementation in #13, without restoring #4's unchecked parameter writer or its nested-mesh limitation. GitHub may mark this original PR merged because the contributor head is preserved in the replacement's ancestry.

Review fixes include path resolution for dissolved and nested instance pages; cycle validation for both command edits and loaded files; validation before publishing a control that could activate a latent cycle, including dry runs; and recognition of valid whitespace in parent() reads. Page records expose only schema-declared controls and compound components. Existing authoring scopes and validated descendant writes remain in place. The lamp fixture now uses the correct parent command context and disposes its runtime.

Validation: focused compiler/domain/runtime tests, typecheck, lint, build, first-import checks and CI pass. All 11 real GPU regression tests across the mesh, projector-path and parent-expression fixtures pass on the Apple M3 Max after enabling Metal access. Earlier adapter failures were session restrictions, not missing machine support; no pixel tests were skipped or weakened. The broader gates had one devices-only helper timeout also reproduced on the unchanged baseline.

The contributor fork could not be updated through the connector, so #14 provides the reviewable repair while preserving contributor history. Local Git history and the separate mapping integration were untouched.

Copy link
Copy Markdown
Owner

Validation follow-up: the isolated landing tree's src/devices/helper.test.ts now passes all 21 tests with unrestricted local execution. This clears the specific helper timeout previously observed under the restricted session. The real GPU fixtures had already passed all 11 checks after Metal access was enabled. This is a targeted rerun of the previously failing file, not a claim that the entire broader gate suite was rerun.

drmbt added a commit to drmbt/loom that referenced this pull request Oct 8, 2026
@drmbt
drmbt deleted the pr/drmbt-parent-expr-2026-10-06 branch October 8, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants